package 集合.泛型;
import java.util.ArrayList;

public class 泛型test {
    public static void main(String[] args) {
        cat c1=new cat();
        c1.setName("波斯猫");
        c1.setAge(2);
        c1.eat1();

        cat c2=new cat();
        c2.setName("狸花猫");
        c2.setAge(3);
        c2.eat2();

        dog d1=new dog();
        d1.setName("狗1");
        d1.setAge(4);
        d1.eat1();

        dog d2=new dog();
        d2.setName("狗2");
        d2.setAge(3);
        d2.eat2();


    }
    public static void keepPet(ArrayList<? extends cat> list){
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
class Animal{
    private String name;
    private int age;

    public Animal() {
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Animal{name = " + name + ", age = " + age + "}";
    }
}
class cat extends Animal{
    public void eat1(){
        System.out.println("一只叫做"+getName()+"的，"+getAge()+"岁的波斯猫，正在吃小饼干");
    }
    public void eat2(){
        System.out.println("一只叫做"+getName()+"的，"+getAge()+"岁的狸花猫，正在吃鱼");
    }
}
class dog extends Animal{
    public void eat1(){
        System.out.println("一只叫做"+getName()+"的，"+getAge()+"岁的泰迪，正在吃骨头，边吃边蹭");
    }
    public void eat2(){
        System.out.println("一只叫做"+getName()+"的，"+getAge()+"岁的哈士奇，正在吃骨头，边吃边拆家");
    }
}
